import java.util.HashSet;

public class LCP44 {
    HashSet<Integer> set = new HashSet<>();
    int count = 0;
    public int numColor(TreeNode root) {
        dfs(root);
        return count;
    }

    private void dfs(TreeNode root) {
        if(root == null) {
            return;
        }
        if(set.add(root.val) == true) {
            count ++;
        }
        dfs(root.left);
        dfs(root.right);
    }
}
